package cn.net.cfss.fgbp.face.console.controller;

import cn.net.cfss.fgbp.api.console.dto.SysUserMenufieldDto;
import cn.net.cfss.fgbp.api.console.inte.ISysUserMenufieldService;
import cn.net.cfss.fgbp.base.controller.BaseController;
import cn.net.cfss.fgbp.face.console.util.ReturnUtil;
import cn.net.cfss.fgbp.face.console.vo.BaseParas;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author wutao
 * @version 1.0
 * @date 2021/3/18 16:24
 */
@RestController
@Slf4j
@RequestMapping("ucenter/menufield")
public class SysUserMenufieldController extends BaseController {

    @Autowired
    private ISysUserMenufieldService sysUserMenufieldService;

    @ApiOperation("用户个性化字段配置-查询")
    @RequestMapping(value = "query", method = RequestMethod.GET)
    public String get(@RequestBody BaseParas baseParas) {
        String menuKey = baseParas.getPlain().getString("menuKey");
        Long userId = getUserId();

        SysUserMenufieldDto search = new SysUserMenufieldDto();
        search.setUserId(userId);
        search.setMenuKey(menuKey);

        SysUserMenufieldDto sysUserMenufieldDto = sysUserMenufieldService.selectOne(search);

        return ReturnUtil.returnSucc(sysUserMenufieldDto);
    }

    @ApiOperation("用户个性化字段配置-保存")
    @RequestMapping(value = "save", method = RequestMethod.GET)
    public String save(@RequestBody BaseParas baseParas) {
        String menuKey = baseParas.getPlain().getString("menuKey");
        String detail = baseParas.getPlain().getString("detail");

        SysUserMenufieldDto dto = new SysUserMenufieldDto();
        dto.setDetail(detail);
        dto.setMenuKey(menuKey);
        sysUserMenufieldService.addOrUpdate(dto);

        return ReturnUtil.returnSucc();
    }
}
